vimfandomcom-20200223-history
Easy word and page selection and deletion in gvim
Perhaps the most useful thing I do in Windows editing (be it in MS Word or Notepad-variant) is to hold down both Ctrl-Shift keys and press either up/down/left/right arrow keys or Home/End/PageUp/PageDown keys to select an area that could encompass word-by-word, line-by-line or page-by-page. This allows me to quickly edit or delete my text. This feature is prominent in Windows and I find myself using it too often with any edit box, like in a web browser or chat messenger. Also, holding down the Ctrl key and pressing either Backspace or Delete keys delete word-by-word. The features mentioned above work differently and are somewhat clumsy in Vim - requiring many keystrokes and often a change from insert to normal mode and back from visual. Some features do not exist. Hence, I thought of combining these features with Vim as a way of bringing Vim closer to the standard editing tools most textboxes have. Plus, this would be a great way for new users to get acquainted with Vim. These mappings utilize the Ctrl & Shift keys that may *NOT* work with terminal versions of Vim. They SHOULD work with GVim. I have set up these mappings to work just the way I would like it to do. They may not conform to how it actually is when the same keystrokes are performed in another editor (e.g. textboxes in Windows or X11). Try it and see if you like it :) No, v is not the same as v. Both 's are necessary to give its effect. I'm slightly dissatisfied with the mapping done when the cursor is at the end of a line. It pulls the next line up and _deletes the first word_. Any ideas on how to prevent it from taking the first word, but still take the eol? "place in vimrc file "word selection nmap vbge nmap vew imap _mz"_xv`zobge imap _my"_xi_mz"_xv`yo`z vmap bge vmap ew "down/up selection nmap v nmap v imap _mz"_xv`zo`z imap _mz"_xv`zo`zo vmap vmap "home/end selection nmap v nmap v imap _mz"_s`zv imap _mz"_xv`zo "half page down/up selection nmap v nmap v imap _mz"_xv`zo imap _mz"_xv`zo vmap vmap "word deletion imap imap _mzewi v`z"_c Comments What is the point of this? Vim's power lies in its modality. If you don't use Vim's modes, there are lots of editors out there that are better for your use. Kate (*nix) and Textpad (Win32) comes to mind. But if you want to use a really powerful editor, I suggest learning to use Vim like it's supposed to be used. After a while what seemed strange at first starts making sense, and you will find out how great a modal editor is. ---- Cream for Vim (http://cream.sf.net) has similar functionality within insert mode, if you like single-mode editing (as this tip suggests). But this is not the "Vim way" which is less right-brained/visual and more left-brained/calculated. ---- :imap bdwi :imap v0di :map b :map 0 The problem is I forget my esoteric mappings, unless they are intuitive and require no switching from left to right brain. ---- I can't seem to use or map my HOME key. It sends me to the top of my window no mater what I try. Is this b/c I'm using terminal vim in unix/CDE? It seems that the operating system gets the HOME and END keys before vim does. Is there anything I can do? In gvim my keys work fine. ---- Things start to get funky in terminal Vim. A lot of the control-key (Ctrl, Shift, Alt) functionality is either lost or varies between different operating systems. I use rxvt on the SunOS unix/CDE with the environmental variable $TERM=dtterm when I have a color terminal. I have this in my vimrc file: "Home, End, BackSpace, Shift-arrow & Shift-function keys for color terminals if &term "dtterm" set t_kh=[7~ t_@7=[8~ t_kb= t_%i=[c t_#4=[d =[a =[b set =[23~ =[24~ =[25~ =[26~ =[28~ =[29~ =[31~ =[32~ =[33~ endif Note that the character that come after every '=' sign for the "set" options is the ESC key character. To enter it within vim, type and then hit - you will get ^[ It should look like "set t_kh=^[[7~" on vim. See . ----